#数据预测
import cv2

image = cv2.imread('E:/Mask_RCNN-master/images/val/110_2_737_345_0.468.png')

from mrcnn import model as modellib, utils
from mrcnn.config import Config


class BalloonConfig(Config):
    """Configuration for training on the toy  dataset.
    Derives from the base Config class and overrides some values.
    """
    # Give the configuration a recognizable name
    NAME = "balloon"

    # We use a GPU with 12GB memory, which can fit two images.
    # Adjust down if you use a smaller GPU.
    IMAGES_PER_GPU = 1

    # Number of classes (including background)
    NUM_CLASSES = 1 + 1  # Background + balloon

    # Skip detections with < 90% confidence
    DETECTION_MIN_CONFIDENCE = 0.8


config = BalloonConfig()

model = modellib.MaskRCNN(mode="inference", config=config,
                          model_dir='logs')

model.load_weights('E:/Mask_RCNN-master/logs/balloon20220602T2044/mask_rcnn_balloon_0030.h5', by_name=True)

result = model.detect([image])
print(result[0])

class_names = ['BG', '1']
from mrcnn.visualize import display_instances

display_instances(image, result[0]['rois'], result[0]['masks'], result[0]['class_ids'], class_names,
                  scores=None, title="",
                  figsize=(16, 16), ax=None,
                  show_mask=True, show_bbox=True,
                  colors=None, captions=None)